﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class ForumProvider : BaseProvider<ForumProvider.RequestDataInfo>, IDataProvider
    {
        public ForumProvider(string _jsonInfo) : base(_jsonInfo)
        {
        }

        public IMessageInfo Do()
        {
            message.data = ProcessResponseData();
            return message;            
        }

        private List<ResponseDataInfo> ProcessResponseData()
        {
            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }

            //use postdata.data to process responseData
            List<ResponseDataInfo> list = new List<ResponseDataInfo>();
            ResponseDataInfo responseData = new ResponseDataInfo();

            List<TbForumEntity> listForum = TbForumManager.Instance().QueryForum(postdata.data.onlygettodayforum, postdata.data.querykey,
                                                                                    postdata.data.timesort,  postdata.data.timesorttype, 
                                                                                    postdata.data.classsort, postdata.data.classsorttype);

            listForum.ForEach(delegate(TbForumEntity entity) { list.Add(new ResponseDataInfo(){
                         forum_id=entity.forumId,forum_date=entity.showDate, forum_name=entity.forumName,forum_address=entity.Place
                        });
                     });

            /*
            if (postdata.data.onlygettodayforum == 1)
            {
                responseData.forum_id = 100;
                responseData.forum_name = "石材养护论坛";
                responseData.forum_date = DateTime.Now.ToString("yyyy年M月d日");
                responseData.forum_address = "上海杨高南路626号国际展览中心";
                list.Add(responseData);
            }
            else
            {
                responseData.forum_id = 101;
                responseData.forum_name = "餐饮企业清洁论坛";
                responseData.forum_date = DateTime.Now.ToString("yyyy年M月d日");
                responseData.forum_address = "上海会展中心1号展馆";
                list.Add(responseData);

                responseData = new ResponseDataInfo();
                responseData.forum_id = 102;
                responseData.forum_name = "\"中国好空气 中国好未来\"主题论坛";
                responseData.forum_date = DateTime.Now.ToString("yyyy年M月d日");
                responseData.forum_address = "上海会展中心1号展馆";
                list.Add(responseData);

            }
            */
            return list;         
        }

        public class RequestDataInfo 
        {
            public int onlygettodayforum { get; set; }
            public string querykey { get; set; }

            public int timesort { get; set; }
            public int timesorttype { get; set; }

            public int classsort { get; set; }
            public int classsorttype { get; set; }

            /**
            onlygettodayforum:1(仅返回今日论坛)或0(忽略)
            querykey:""搜索词"",
            timesort:1或0,
            timesortfunction:1(升序)或0(降序),
            classsort:1或0,
            classsortfunction:1(升序)或0(降序)
             **/

        }

        public class ResponseDataInfo
        {
            /* ""forum_id"":论坛编号,
               ""forum_name"":""论坛名称"",
               ""forum_date"":""时间"",
               ""forum_address"":""地点""*/
            public int forum_id { get; set; }
            public string forum_name { get; set; }
            public string forum_date { get; set; }
            public string forum_address { get; set; }
        }


    }
}
